package work812;

import java.io.*;

public class work4 {
  static ObjectInputStream ois = null;
  static ObjectOutputStream oos = null;
  public static void saveStaffToFile(Staff staff, File file){
    try {
     String s = staff.getName()+"/"+staff.getAge()+"/"+staff.getSalary();
      oos = new ObjectOutputStream(new FileOutputStream(file));
      oos.write(s.getBytes());
      oos.flush();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }


  public static void main(String[] args) {
    Staff staff1 = new Staff("小明",20,9999);
    Staff staff2 = new Staff("小暗",22,10000);
    File f = new File("E:\\bdqn\\javaDemo\\2.txt");
    try {
      oos = new ObjectOutputStream(new FileOutputStream(f));
      oos.writeObject(staff1);
      oos.writeObject(staff2);
      oos.flush();
      ois = new ObjectInputStream(new FileInputStream(f));
      System.out.println(ois.readObject());
      System.out.println(ois.readObject());
      System.out.println("========================================");
      Staff staff = new Staff("Tom", 30, 5000);
      File file = new File("E:\\bdqn\\javaDemo\\2.txt");
      work4.saveStaffToFile(staff, file);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        ois.close();
        oos.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }


  }
}
